//
//  BIDSetThemeViewController.m
//  cxgov
//
//  Created by mal on 16/3/16.
//  Copyright © 2016年 mal. All rights reserved.
//

#import "BIDSetThemeViewController.h"

@interface BIDSetThemeViewController ()

@end

@implementation BIDSetThemeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"更换皮肤";
    // Do any additional setup after loading the view from its nib.
    UITapGestureRecognizer *tapGR1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler1)];
    UITapGestureRecognizer *tapGR2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler2)];
    UITapGestureRecognizer *tapGR3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler3)];
    
    [_imgView1 addGestureRecognizer:tapGR1];
    [_imgView2 addGestureRecognizer:tapGR2];
    [_imgView3 addGestureRecognizer:tapGR3];
    //
    [self setTheme];
}

- (void)setTheme
{
    _imgView1.image = [UIImage imageNamed:@"theme_inchoose.png"];
    _imgView2.image = [UIImage imageNamed:@"theme_inchoose.png"];
    _imgView3.image = [UIImage imageNamed:@"theme_inchoose.png"];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSNumber *themeValue = [userDefaults objectForKey:@"theme"];
    NSString *viewBgImgName = @"";
    switch([themeValue intValue])
    {
        case 1:
        {
            viewBgImgName = @"viewBg.jpg";
            _imgView1.image = [UIImage imageNamed:@"theme_choose.png"];
        }
            break;
        case 2:
        {
            viewBgImgName = @"viewBg2.jpg";
            _imgView2.image = [UIImage imageNamed:@"theme_choose.png"];
        }
            break;
        case 3:
        {
            viewBgImgName = @"viewBg3.jpg";
            _imgView2.image = [UIImage imageNamed:@"theme_choose.png"];
        }
            break;
    }
    _bgImgView.image = [UIImage imageNamed:viewBgImgName];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)tapGestureHandler1
{
    _imgView1.image = [UIImage imageNamed:@"theme_choose.png"];
    _imgView2.image = [UIImage imageNamed:@"theme_inchoose.png"];
    _imgView3.image = [UIImage imageNamed:@"theme_inchoose.png"];
    //
    _bgImgView.image = [UIImage imageNamed:@"viewBg.jpg"];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:@1 forKey:@"theme"];
    [userDefaults synchronize];
    //[[NSNotificationCenter defaultCenter] postNotificationName:UPDATE_THEME object:self];
}

- (void)tapGestureHandler2
{
    _imgView1.image = [UIImage imageNamed:@"theme_inchoose.png"];
    _imgView2.image = [UIImage imageNamed:@"theme_choose.png"];
    _imgView3.image = [UIImage imageNamed:@"theme_inchoose.png"];
    //
    _bgImgView.image = [UIImage imageNamed:@"viewBg2.jpg"];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:@2 forKey:@"theme"];
    [userDefaults synchronize];
    //[[NSNotificationCenter defaultCenter] postNotificationName:UPDATE_THEME object:self];
}

- (void)tapGestureHandler3
{
    _imgView1.image = [UIImage imageNamed:@"theme_inchoose.png"];
    _imgView2.image = [UIImage imageNamed:@"theme_inchoose.png"];
    _imgView3.image = [UIImage imageNamed:@"theme_choose.png"];
    //
    _bgImgView.image = [UIImage imageNamed:@"viewBg3.jpg"];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:@3 forKey:@"theme"];
    [userDefaults synchronize];
    //[[NSNotificationCenter defaultCenter] postNotificationName:UPDATE_THEME object:self];
}

@end
